import { IBaseBehavior } from "./base/IBaseBehavior";
import { IBehaviorTree } from "./base/IBehaviorTree";
import { IBlackboard } from "./base/IBlackboard";

export class BTContext {
    private _tree: IBehaviorTree = null;
    private _blackboard: IBlackboard = null;

    private _nodeList: IBaseBehavior[] = [];

    public set tree(value: IBehaviorTree) {
        this._tree = value;
    }

    public get tree(): IBehaviorTree {
        return this._tree;
    }

    public get blackboard(): IBlackboard {
        return this._blackboard;
    }

    public set blackboard(value: IBlackboard) {
        this._blackboard = value;
    }

    enterBehavior(node: IBaseBehavior): void {
        this._nodeList.push(node);
    }

    exitBehavior(node: IBaseBehavior): void {
        for (let i = 0; i < this._nodeList.length; i++) {
            const tmp = this._nodeList[i];
            if (tmp == node) {
                this._nodeList.splice(i, 1);
                break;
            }
        }
    }
}